#include <stdio.h>
#include <stdlib.h>
#include "SDL/SDL.h"

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination) 
{ 

//Holds offsets
SDL_Rect* clip=NULL;

 SDL_Rect offset; 

//Get offsets 

offset.x = x; 
offset.y = y; 
//Blit 
SDL_BlitSurface( source, clip, destination, &offset ); 

}





int main( int argc, char* args[] ) { 

//The images 
SDL_Surface* hello = NULL; 
SDL_Surface* screen = NULL;
SDL_Surface* star = NULL; 
SDL_Surface* tstar = NULL;
SDL_Surface* hstar = NULL;

 int i,j=0;
int x, y;
int h, t;

int stars_count = 3461;		//test

//Start SDL 
SDL_Init( SDL_INIT_EVERYTHING ); 
//Set up screen 
screen = SDL_SetVideoMode( 400, 200, 24, SDL_SWSURFACE ); 


for(j; j<10; j++){	//this will be while(1)
///////////////

//reading stars_count from seg_count here



///////////////
//Load image 
hello = SDL_LoadBMP( "logo.bmp" );
star = SDL_LoadBMP( "star.bmp" );
tstar = SDL_LoadBMP( "tstar.bmp" );
hstar = SDL_LoadBMP( "hstar.bmp" );

//Apply image to screen 
SDL_BlitSurface( hello, NULL, screen, NULL ); 

//max 6400 segments shown

//stars_count = how many segments we have
h = stars_count / 100;
t = (stars_count-100*h) / 10;
i = stars_count - (100*h +10*t);

x=0; y=0;

for (h; h>0; h--){
apply_surface( 160+x, 0+y, hstar, screen );
x+=30;

if (x==240){x=0; y+=25;}
}



for (t; t>0; t--){
apply_surface( 160+x, 0+y, tstar, screen );
x+=30;

if (x==240){x=0; y+=25;}
}



for (i; i>0; i--){

	apply_surface( 160+x, 0+y, star, screen );
x+=30;

if (x==240){x=0; y+=25;}
	 
}



//Update Screen 
SDL_Flip( screen ); 
//Pause 
SDL_Delay( 2000 ); //should be 10*theartbeat time


}
//Free the loaded image 
SDL_FreeSurface( hello ); 
//Quit SDL 

SDL_Quit(); 
return 0; 
}
